<!--# include virtual="/admin/common/html/header.html"-->
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 政策法规<span class="c-gray en">&gt;</span>栏目管理<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		标题：
		<input type="text" name="fieldName" id="fieldName" placeholder="标题" style="width:250px" class="input-text">
		<button name="searchButton" id="searchButton" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>搜索	</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="policies_field_edit(this,'addField.html')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe6e2;</i> 新增栏目</a>
		<!--<a href="javascript:;" onclick="deletes()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> -->
		</span> <span class="r"></span> </div>
	<div class="mt-20">
		<table id="firm-post-list"  class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th ><input type="checkbox" name="test" value=""></th>
					<th >标题</th>
					<th >父标题</th>
					<th >创建时间</th>
					<th >操作</th>									
				</tr>
			</thead>
			<tbody ></tbody>
		</table>				
	</div>
</div>
<!--# include virtual="/admin/common/html/_footer.html"-->
<script type="text/javascript" src="../../lib/datatables/1.10.12/jquery.dataTables.js"></script>
<script type="text/javascript">
    $(function () {
        var $table_id = $("#firm-post-list");
        var user = {
            getQueryCondition: function (data) {
                var param = {};
                param.fieldName= $.trim($("#fieldName").val());                              
                param.pageNumber = data.start;
                param.pageSize = data.length;
                param.draw = 1;
                return param;
            }
        };
        //object可以如下初始化表格
         var dataTable = $table_id.DataTable({
            dom: '<".table_area_top" B and >t<".table_area_bottom" pi>',
            Filter: false, //列筛序功能
            searching: false,//本地搜索
            ordering: true, //排序功能
            Info: true,//页脚信息
            lengthMenu: [15],//定义每页显示数据数量
            scrollY: "auto",
            Paginate: true, //翻页功能
            sortable: false,
            processing: true,
            serverSide: true,      
            ajax: function (data, callback){//ajax配置为function,手动调用异步查询
            	console.log(user.getQueryCondition(data));
                $.ajax({
                    type: "post",
                    url: "/guidance_service/front/policies/field/searchField.do",
                    data: user.getQueryCondition(data),
                    cache: false,  //禁用缓存
                    dataType: "json",
                    success: function (result) {
                    	console.log(result);
                        //封装返回数据，这里仅演示了修改属性名
                        var returnData = {};
                        returnData.recordsTotal = result.ext.recordsTotal;
                        returnData.recordsFiltered = result.ext.recordsFiltered;//后台不实现过滤功能，每次查询均视作全部结果
                        returnData.data = result.data;
                        callback(returnData);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg("查询失败,请检查搜索条件！", {icon: 2, time: 1000});
                    }
                });
            },
            //使用对象数组，一定要配置columns，告诉 DataTables 每列对应的属
            //data 这里是固定不变的，id，name，age，sex等为你数据里对应的属性
            		
            columns: [
            	{
                    data: "fieldId",
                    render: function (data) {
						return '<input type="checkbox" name="fieldId" value="'+data+'" class="fieldId">';
						
                    }
                },
                {
                    data: "fieldName",//栏目标题
                    render: function (data) {
				  		return data || "";
                    }
          	    },
          	    {
                    data: "fieName",//父标题
                    render: function (data) {
				  		return data || "";
                    }
          	    },
                {
                    data: "createTime",//发布时间
                    render: function (data) {
                    	return data;
                    }
                },               
                {
                    data: "fieldId",                      
                    render: function (data,type,row) {
                        return '<a style="text-decoration:none" class="ml-5" onClick="policies_field_edit(this,\'addField.html?fieldId='+data+'\')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>'+
                    		'<a style="text-decoration:none" class="ml-5" onClick="policies_field_del(this,'+data+','+row.fieldParantId+')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                    }
                }
            ],
            language: { //国际语言转化
                aria: {
                    sortAscending: " - click/return to sort ascending",
                    sortDescending: " - click/return to sort descending"
                }, 
                
                lengthMenu: "显示 _MENU_ 记录",
                zeroRecords: "对不起，查询不到任何相关数据",
                emptyTable: "未有相关数据",
                loadingRecords: "正在加载数据-请等待...",
                info: "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录。",
                infoEmpty: "当前显示0到0条，共0条记录",
                infoFiltered: "（数据库中共为 _MAX_ 条记录）",
                processing: " 正在加载数据...",
                //多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt
                paginate: {
                    first: "首页",
                    previous: " 上一页 ",
                    next: " 下一页 ",
                    last: " 尾页 "
                }
            },
            "drawCallback": function (settings) {
                var api = this.api();
               // console.log(api.rows({page: 'current'}).data());
            }
        });

        $("#searchButton").on("click", function () {
            dataTable.draw();
        });

        $("body").on("change", ":checkbox", function () {
            if ($(this).is("[name='checkBtn']")) {
                //全选
                $(":checkbox", $table_id).prop("checked", $(this).prop("checked"));
            } else {
                //一般复选
                var checkbox = $("tbody :checkbox", $table_id);
                $(":checkbox[name='checkBtn']", $table_id).prop('checked', checkbox.length == checkbox.filter(':checked').length);
            }
        }).on("click", ".td-checkbox", function (event) {
            //点击单元格即点击复选框
            !$(event.target).is(":checkbox") && $(":checkbox", this).trigger("click");
        })
    });
</script>
<script type="text/javascript">
/* $(function(){
	$('.table-sort').dataTable({
		"aaSorting": [[ 1, "desc" ]],//默认第几个排序
		"bStateSave": true,//状态保存
		"aoColumnDefs": [
		  {"bVisible": false, "aTargets": [ 3 ]}, //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,11,12]}// 制定列不参与排序
		]
	});	
}); */



/*标签-删除*/
function policies_field_del(obj,fieldId,fieldParantId){
	layer.confirm('确认要删除吗？',function(index){
		$.post("/guidance_service/front/policies/field/logicDelete.do",{"fieldId":fieldId,"fieldParantId":fieldParantId},function(result){
			console.log(fieldId);
			if(result.resultCode == 200){
				/*$(obj).parents("tr").remove();*/
				layer.msg('已删除!',{icon:1,time:1000});
				parent.location.href=parent.location.href;              
              	layer_close();
			}else{
				layer.msg(result.message,{icon:2,time:1000});
			}
		});
	});
}
//批量删除
function deletes(){
	var Ids ="";  
	$('input[name="fieldId"]:checked').each(function(){    
		Ids+=$(this).val()+",";    
	});
	if(Ids.length>0){
		layer.confirm('确认要删除吗？',function(index){
			$.post("/guidance_service/front/policies/field/logicDeleteAll.do",{"fieldId":Ids},function(result){
				console.log(result.resultCode);
				if(result.resultCode == 200){
					layer.msg('已删除!',{icon:1,time:1000},function(){
						location.replace(location.href);
					});
				}else{
					layer.msg(result.message,{icon:2,time:1000});
				}
			});
		});
	}else{
		layer.msg("你还没有选择要删除的内容！",{icon:2,time:1000});
	}	
}

/*文章-编辑*/
function policies_field_edit(obj,url,id,w,h){
	var index = layer.open({
		type: 2,
		title: '',
		content: url
	});
	layer.full(index);
}

</script> 
</body>
</html>